//#ifndef THREE_PHASE_METER_LIB_H
//#define THREE_PHASE_METER_LIB_H

///**************************************************************
// * ThreePhaseMeterLib - 三相电流电压测量仪表C语言库
// * 
// * 功能：三相电路电流、电压、频率等参数的采集、处理及通信
// * 适用设备：三相电流电压表（支持三相四线Y34和三相三线V33接线）
// * 版本：V1.0.0
// * 日期：2025-10-02
// **************************************************************/

//#include <stdint.h>
//#include <stddef.h>
//#include <string.h>
//#include <stdio.h>

///************************ 硬件参数定义 ************************/
//// 信号输入参数
//#define VOLTAGE_RANGE_400V    400     // 电压测量量程：400V
//#define VOLTAGE_RANGE_100V    100     // 电压测量量程：100V
//#define CURRENT_RANGE_5A      5       // 电流测量量程：5A
//#define CURRENT_RANGE_1A      1       // 电流测量量程：1A

//// 过载保护参数
//#define VOLTAGE_OVERLOAD_CONT 1.2     // 电压持续过载倍数（1.2倍）
//#define VOLTAGE_OVERLOAD_INST 2.0     // 电压瞬时过载倍数（2倍）
//#define CURRENT_OVERLOAD_CONT 1.2     // 电流持续过载倍数（1.2倍）
//#define CURRENT_OVERLOAD_INST 2.0     // 电流瞬时过载倍数（2倍）

//// 功耗参数
//#define POWER_CONSUME_VOLTAGE 1       // 电压测量回路功耗 <1VA
//#define POWER_CONSUME_CURRENT 1       // 电流测量回路功耗 <1VA

//// 频率参数
//#define FREQ_MIN              40      // 最小测量频率 Hz
//#define FREQ_MAX              65      // 最大测量频率 Hz

//// 电源参数
//#define POWER_SUPPLY_MIN      80      // 最小供电电压 V
//#define POWER_SUPPLY_MAX      270     // 最大供电电压 V

//// 通信参数
//#define COMM_BAUDRATE_MIN     1200    // 最小波特率
//#define COMM_BAUDRATE_MAX     9600    // 最大波特率
//#define COMM_PROTOCOL_MODBUS  0       // MODBUS-RTU
//#define COMM_PROTOCOL_DLT645  1       // DLT645-2007

///************************ 数据结构定义 ************************/
//// -------------------------- 枚举定义 --------------------------
//// MODBUS 数据类型
//typedef enum {
//    DATA_TYPE_UINT8,    // 8位无符号整数
//    DATA_TYPE_UINT16,   // 16位无符号整数
//    DATA_TYPE_UINT32,   // 32位无符号整数
//    DATA_TYPE_FLOAT,    // 32位浮点数
//    DATA_TYPE_INVALID   // 无效类型
//} ModbusDataType;

//// MODBUS 参数分类
//typedef enum {
//    CATEGORY_BASIC_ELEC,    // 基础电参数
//    CATEGORY_POWER,         // 功率参数
//    CATEGORY_ENERGY,        // 电能参数
//    CATEGORY_EPS,           // EPS 专用参数
//    CATEGORY_HARMONIC,      // 谐波参数
//    CATEGORY_COMM           // 通信参数
//} ModbusParamCategory;

//// -------------------------- MODBUS 地址表定义 --------------------------
//// 单个地址的配置信息
//typedef struct {
//    uint16_t address;               // MODBUS 寄存器地址
//    const char* param_name;         // 参数名称
//    ModbusDataType data_type;       // 数据类型
//    const char* unit;               // 单位
//    ModbusParamCategory category;   // 参数分类
//    size_t data_offset;             // 在 ThreePhaseData 结构体中的偏移量
//} ModbusAddressTable;

//// MODBUS 数据结构体
//typedef struct {
//    // 基础电参数（0x00~0x06）
//    float    A_voltage;         // 0x00
//    float    B_voltage;         // 0x01
//    float    C_voltage;         // 0x02
//    float    A_current;         // 0x03
//    float    B_current;         // 0x04
//    float    C_current;         // 0x05
//    float    neutral_current;   // 0x06

//    // 功率参数（0x07~0x16）
//    uint16_t total_active_power;    // 0x07
//    uint16_t A_active_power;        // 0x08
//    uint16_t B_active_power;        // 0x09
//    uint16_t C_active_power;        // 0x0A
//    uint16_t total_reactive_power;  // 0x0B
//    uint16_t A_reactive_power;      // 0x0C
//    uint16_t B_reactive_power;      // 0x0D
//    uint16_t C_reactive_power;      // 0x0E
//    uint16_t total_apparent_power;  // 0x0F
//    uint16_t A_apparent_power;      // 0x10
//    uint16_t B_apparent_power;      // 0x11
//    uint16_t C_apparent_power;      // 0x12
//    float    total_power_factor;    // 0x13
//    float    A_power_factor;        // 0x14
//    float    B_power_factor;        // 0x15
//    float    C_power_factor;        // 0x16

//    // 频率/电能参数（0x17~0x23）
//    float    A_line_voltage;                // 0x17
//    float    B_line_voltage;                // 0x18
//    float    C_line_voltage;                // 0x19
//    float    A_frequency;                   // 0x1A
//    float    C_frequency;                   // 0x1B
//    float    forward_active_energy_high;    // 0x1C
//    float    forward_active_energy_low;     // 0x1D
//    float    reverse_active_energy_high;    // 0x1E
//    float    reverse_active_energy_low;     // 0x1F
//    float    forward_reactive_energy_high;  // 0x20
//    float    forward_reactive_energy_low;   // 0x21
//    float    reverse_reactive_energy_high;  // 0x22
//    float    reverse_reactive_energy_low;   // 0x23

//    // EPS 专用参数（0x46~0x47、0x2001~0x2004）
//    uint16_t alarm_output;                  // 0x46
//    uint16_t switch_digital_input;          // 0x47
//    float    EPS_total_active_energy_high;  // 0x2001
//    float    EPS_total_active_energy_low;   // 0x2002
//    float    EPS_total_reactive_energy_high;// 0x2003
//    float    EPS_total_reactive_energy_low; // 0x2004

//    // 通信/配置参数（0x50~0x57）
//    uint16_t password;                      // 0x50
//    uint8_t  comm_address;                  // 0x51
//    uint32_t baud_rate;                     // 0x52
//    uint8_t  parity;                        // 0x53
//    uint8_t  wiring_mode;                   // 0x55
//    float    max_voltage;                   // 0x56
//    float    max_current;                   // 0x57

//    // 谐波参数（0x70~0x75）
//    uint16_t THD_Ua;                        // 0x70
//    uint16_t THD_Ub;                        // 0x71
//    uint16_t THD_Uc;                        // 0x72
//    uint16_t THD_Ia;                        // 0x73
//    uint16_t THD_Ib;                        // 0x74
//    uint16_t THD_Ic;                        // 0x75
//} ThreePhaseData;

//// MODBUS 地址表（offsetof 自动计算偏移量）
//ModbusAddressTable g_ThreePhaseMeter_addr_table[] = {
//    // 基础电参数
//    {0x00, "A相电压",        DATA_TYPE_FLOAT,  "V",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, A_voltage)},
//    {0x01, "B相电压",        DATA_TYPE_FLOAT,  "V",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, B_voltage)},
//    {0x02, "C相电压",        DATA_TYPE_FLOAT,  "V",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, C_voltage)},
//    {0x03, "A相电流",        DATA_TYPE_FLOAT,  "A",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, A_current)},
//    {0x04, "B相电流",        DATA_TYPE_FLOAT,  "A",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, B_current)},
//    {0x05, "C相电流",        DATA_TYPE_FLOAT,  "A",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, C_current)},
//    {0x06, "零线电流",       DATA_TYPE_FLOAT,  "A",     CATEGORY_BASIC_ELEC, offsetof(ThreePhaseData, neutral_current)},

//    // 功率参数
//    {0x07, "总有功功率",     DATA_TYPE_UINT16, "W",     CATEGORY_POWER,      offsetof(ThreePhaseData, total_active_power)},
//    {0x08, "A相有功功率",    DATA_TYPE_UINT16, "W",     CATEGORY_POWER,      offsetof(ThreePhaseData, A_active_power)},
//    {0x09, "B相有功功率",    DATA_TYPE_UINT16, "W",     CATEGORY_POWER,      offsetof(ThreePhaseData, B_active_power)},
//    {0x0A, "C相有功功率",    DATA_TYPE_UINT16, "W",     CATEGORY_POWER,      offsetof(ThreePhaseData, C_active_power)},
//    {0x0B, "总无功功率",     DATA_TYPE_UINT16, "Var",   CATEGORY_POWER,      offsetof(ThreePhaseData, total_reactive_power)},
//    {0x0C, "A相无功功率",    DATA_TYPE_UINT16, "Var",   CATEGORY_POWER,      offsetof(ThreePhaseData, A_reactive_power)},
//    {0x0D, "B相无功功率",    DATA_TYPE_UINT16, "Var",   CATEGORY_POWER,      offsetof(ThreePhaseData, B_reactive_power)},
//    {0x0E, "C相无功功率",    DATA_TYPE_UINT16, "Var",   CATEGORY_POWER,      offsetof(ThreePhaseData, C_reactive_power)},
//    {0x0F, "总视在功率",     DATA_TYPE_UINT16, "VA",    CATEGORY_POWER,      offsetof(ThreePhaseData, total_apparent_power)},
//    {0x10, "A相视在功率",    DATA_TYPE_UINT16, "VA",    CATEGORY_POWER,      offsetof(ThreePhaseData, A_apparent_power)},
//    {0x11, "B相视在功率",    DATA_TYPE_UINT16, "VA",    CATEGORY_POWER,      offsetof(ThreePhaseData, B_apparent_power)},
//    {0x12, "C相视在功率",    DATA_TYPE_UINT16, "VA",    CATEGORY_POWER,      offsetof(ThreePhaseData, C_apparent_power)},
//    {0x13, "总功率因数",     DATA_TYPE_FLOAT,  "",      CATEGORY_POWER,      offsetof(ThreePhaseData, total_power_factor)},
//    {0x14, "A相功率因数",    DATA_TYPE_FLOAT,  "",      CATEGORY_POWER,      offsetof(ThreePhaseData, A_power_factor)},
//    {0x15, "B相功率因数",    DATA_TYPE_FLOAT,  "",      CATEGORY_POWER,      offsetof(ThreePhaseData, B_power_factor)},
//    {0x16, "C相功率因数",    DATA_TYPE_FLOAT,  "",      CATEGORY_POWER,      offsetof(ThreePhaseData, C_power_factor)},

//    // 频率/电能参数
//    {0x17, "A相线电压",      DATA_TYPE_FLOAT,  "V",     CATEGORY_ENERGY,     offsetof(ThreePhaseData, A_line_voltage)},
//    {0x18, "B相线电压",      DATA_TYPE_FLOAT,  "V",     CATEGORY_ENERGY,     offsetof(ThreePhaseData, B_line_voltage)},
//    {0x19, "C相线电压",      DATA_TYPE_FLOAT,  "V",     CATEGORY_ENERGY,     offsetof(ThreePhaseData, C_line_voltage)},
//    {0x1A, "A相频率",        DATA_TYPE_FLOAT,  "Hz",    CATEGORY_ENERGY,     offsetof(ThreePhaseData, A_frequency)},
//    {0x1B, "C相频率",        DATA_TYPE_FLOAT,  "Hz",    CATEGORY_ENERGY,     offsetof(ThreePhaseData, C_frequency)},
//    {0x1C, "正向有功电能(高)",DATA_TYPE_FLOAT, "kWh",   CATEGORY_ENERGY,     offsetof(ThreePhaseData, forward_active_energy_high)},
//    {0x1D, "正向有功电能(低)",DATA_TYPE_FLOAT, "kWh",   CATEGORY_ENERGY,     offsetof(ThreePhaseData, forward_active_energy_low)},
//    {0x1E, "反向有功电能(高)",DATA_TYPE_FLOAT, "kWh",   CATEGORY_ENERGY,     offsetof(ThreePhaseData, reverse_active_energy_high)},
//    {0x1F, "反向有功电能(低)",DATA_TYPE_FLOAT, "kWh",   CATEGORY_ENERGY,     offsetof(ThreePhaseData, reverse_active_energy_low)},
//    {0x20, "正向无功电能(高)",DATA_TYPE_FLOAT, "kVarh", CATEGORY_ENERGY,     offsetof(ThreePhaseData, forward_reactive_energy_high)},
//    {0x21, "正向无功电能(低)",DATA_TYPE_FLOAT, "kVarh", CATEGORY_ENERGY,     offsetof(ThreePhaseData, forward_reactive_energy_low)},
//    {0x22, "反向无功电能(高)",DATA_TYPE_FLOAT, "kVarh", CATEGORY_ENERGY,     offsetof(ThreePhaseData, reverse_reactive_energy_high)},
//    {0x23, "反向无功电能(低)",DATA_TYPE_FLOAT, "kVarh", CATEGORY_ENERGY,     offsetof(ThreePhaseData, reverse_reactive_energy_low)},

//    // EPS 专用参数
//    {0x46,   "报警输出",             DATA_TYPE_UINT16, "",      CATEGORY_EPS, offsetof(ThreePhaseData, alarm_output)},
//    {0x47,   "开关量输入",           DATA_TYPE_UINT16, "",      CATEGORY_EPS, offsetof(ThreePhaseData, switch_digital_input)},
//    {0x2001, "EPS总有功电能(高)",    DATA_TYPE_FLOAT,  "kWh",   CATEGORY_EPS, offsetof(ThreePhaseData, EPS_total_active_energy_high)},
//    {0x2002, "EPS总有功电能(低)",    DATA_TYPE_FLOAT,  "kWh",   CATEGORY_EPS, offsetof(ThreePhaseData, EPS_total_active_energy_low)},
//    {0x2003, "EPS总无功电能(高)",    DATA_TYPE_FLOAT,  "kVarh", CATEGORY_EPS, offsetof(ThreePhaseData, EPS_total_reactive_energy_high)},
//    {0x2004, "EPS总无功电能(低)",    DATA_TYPE_FLOAT,  "kVarh", CATEGORY_EPS, offsetof(ThreePhaseData, EPS_total_reactive_energy_low)},

//    // 通信/配置参数
//    {0x50, "密码",              DATA_TYPE_UINT16, "",     CATEGORY_COMM, offsetof(ThreePhaseData, password)},
//    {0x51, "通信地址",          DATA_TYPE_UINT8,  "",     CATEGORY_COMM, offsetof(ThreePhaseData, comm_address)},
//    {0x52, "波特率",            DATA_TYPE_UINT32, "",     CATEGORY_COMM, offsetof(ThreePhaseData, baud_rate)},
//    {0x53, "校验位",            DATA_TYPE_UINT8,  "",     CATEGORY_COMM, offsetof(ThreePhaseData, parity)},
//    {0x55, "接线方式",          DATA_TYPE_UINT8,  "",     CATEGORY_COMM, offsetof(ThreePhaseData, wiring_mode)},
//    {0x56, "最大电压档位",      DATA_TYPE_FLOAT,  "V",    CATEGORY_COMM, offsetof(ThreePhaseData, max_voltage)},
//    {0x57, "最大电流档位",      DATA_TYPE_FLOAT,  "A",    CATEGORY_COMM, offsetof(ThreePhaseData, max_current)},

//    // 谐波参数
//    {0x70, "A相电压总谐波含量", DATA_TYPE_UINT16, "%",    CATEGORY_HARMONIC, offsetof(ThreePhaseData, THD_Ua)},
//    {0x71, "B相电压总谐波含量", DATA_TYPE_UINT16, "%",    CATEGORY_HARMONIC, offsetof(ThreePhaseData, THD_Ub)},
//    {0x72, "C相电压总谐波含量", DATA_TYPE_UINT16, "%",    CATEGORY_HARMONIC, offsetof(ThreePhaseData, THD_Uc)},
//    {0x73, "A相电流总谐波含量", DATA_TYPE_UINT16, "%",    CATEGORY_HARMONIC, offsetof(ThreePhaseData, THD_Ia)},
//    {0x74, "B相电流总谐波含量", DATA_TYPE_UINT16, "%",    CATEGORY_HARMONIC, offsetof(ThreePhaseData, THD_Ib)},
//    {0x75, "C相电流总谐波含量", DATA_TYPE_UINT16, "%",    CATEGORY_HARMONIC, offsetof(ThreePhaseData, THD_Ic)},
//};

//// 地址表条目数
//#define THREE_PHASE_METER_ADDR_TABLE_SIZE (sizeof(g_ThreePhaseMeter_addr_table) / sizeof(ModbusAddressTable))

//extern ThreePhaseData g_ThreePhaseMeter_data;

//#endif  /* THREE_PHASE_METER_LIB_H */